Skip to content

Conversation

@smitterl
Copy link
Contributor

@smitterl smitterl commented Jan 23, 2026

host_iface: was handled in code but never read from config; add to config
remote_host_iface: was always discovered; now make configurable

default behavior maintained

also apply 'black' formatting for CI

Summary by CodeRabbit

  • Tests
    • Added new configuration parameters for interface handling during virtual network migration tests.
    • Refactored test code for improved readability and consistency across operations and VM definition calls.
    • Enhanced interface selection logic with fallback mechanisms during test cleanup.

✏️ Tip: You can customize this high-level summary in your review settings.

host_iface: was handled in code but never read from config; add to
config
remote_host_iface: was always discovered; now make configurable

default behavior maintained

Signed-off-by: Sebastian Mitterle <[email protected]>
@smitterl smitterl requested a review from nanli1 January 23, 2026 12:00
@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

Walkthrough

This pull request modifies the Ethernet interface migration test by adding two new configuration parameters (host_iface and remote_host_iface) and refactoring the corresponding Python test module. The configuration file introduces interface binding parameters for migration testing. The Python file applies string quoting standardization, reformats function calls for consistency, introduces conditional retrieval logic for remote host interface parameters with a fallback mechanism, and improves the host interface selection logic during cleanup operations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'virtual_network/migrate_with_ethernet: enable host iface settings' directly describes the main change—adding configuration support for host interface settings in the migration test.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@smitterl
Copy link
Contributor Author

running tests now

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@libvirt/tests/src/virtual_network/migrate/migrate_with_ethernet_interface.py`:
- Around line 183-189: The cleanup uses unpr_user directly in shell-interpolated
commands (remote_session.cmd and process.run), which risks injection; change
both calls to avoid shell string interpolation by passing argv lists (e.g., pass
["pkill", "-u", unpr_user] and ["userdel", "-f", "-r", unpr_user] to process.run
with shell=False) or, if the remote session API only accepts a command string,
safely escape the username with shlex.quote before composing the command; update
the remote_session.cmd invocation and the process.run call to use these safe
forms and ensure ignore_status behavior is preserved.

Comment on lines +183 to +189
remote_session.cmd(f"pkill -u {unpr_user};userdel -f -r {unpr_user}")
remote_session.close()
process.run(f'pkill -u {unpr_user};userdel -f -r {unpr_user}',
shell=True, ignore_status=True)
process.run(
f"pkill -u {unpr_user};userdel -f -r {unpr_user}",
shell=True,
ignore_status=True,
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid shell command construction with untrusted user input.

unpr_user is configurable; interpolating it into shell strings risks command injection. Prefer argv lists and/or quoting.

🔒 Suggested fix (avoid shell strings)
@@
-import logging
+import logging
+import shlex
@@
-        if remote_session:
-            remote_session.cmd(f"pkill -u {unpr_user};userdel -f -r {unpr_user}")
+        if remote_session:
+            safe_user = shlex.quote(unpr_user)
+            remote_session.cmd(f"pkill -u {safe_user}; userdel -f -r {safe_user}")
             remote_session.close()
-        process.run(
-            f"pkill -u {unpr_user};userdel -f -r {unpr_user}",
-            shell=True,
-            ignore_status=True,
-        )
+        process.run(["pkill", "-u", unpr_user], ignore_status=True)
+        process.run(["userdel", "-f", "-r", unpr_user], ignore_status=True)
🧰 Tools
🪛 Ruff (0.14.13)

185-185: Function call with shell=True parameter identified, security issue

(S604)

🤖 Prompt for AI Agents
In `@libvirt/tests/src/virtual_network/migrate/migrate_with_ethernet_interface.py`
around lines 183 - 189, The cleanup uses unpr_user directly in
shell-interpolated commands (remote_session.cmd and process.run), which risks
injection; change both calls to avoid shell string interpolation by passing argv
lists (e.g., pass ["pkill", "-u", unpr_user] and ["userdel", "-f", "-r",
unpr_user] to process.run with shell=False) or, if the remote session API only
accepts a command string, safely escape the username with shlex.quote before
composing the command; update the remote_session.cmd invocation and the
process.run call to use these safe forms and ensure ignore_status behavior is
preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant